<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="fragments/easyui_insdep_head :: easyui_insdep_head" th:with="title='商品标签管理'">
</head>

<body>
<div class="easyui-layout" style="width:100%;height:100%;overflow: hidden">
    <div data-options="region:'west',collapsible:false" style="width:50%;overflow: hidden">
        <div class="easyui-layout" style="width:100%;height:100%;overflow: hidden">
            <div data-options="region:'west',collapsible:false" style="width:50%;overflow: hidden">
                <div class="easyui-panel" style="padding:5px;height: 100%">
                    <ul id="tt" class="easyui-tree" method="get"  data-options="url:'/wareParameterDetail/'"></ul>
                </div>
            </div>

            <div data-options="region:'east',collapsible:false" style="width:50%;overflow: hidden">
                <table id="component_tt" class="easyui-datagrid" style="width:100%;height:100%"
                       url="/component/" singleSelect="true" method="get"
                >
                    <thead>
                    <tr>
                        <th field="compName" style="width:95%;">配件类型</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>

    <div data-options="region:'east',collapsible:false" style="width:50%;overflow: hidden">
        <div class="easyui-layout" style="width:100%;height:100%;overflow: hidden">
            <div data-options="region:'west',collapsible:false" style="width:50%;overflow: hidden">
                <table id="cp_tt" class="easyui-datagrid" style="width:100%;height:100%"
                       url="/componentParameter/"  singleSelect="true" method="get"
                >
                    <thead>
                    <tr>
                        <th field="compParamName" style="width:95%;">配件属性</th>
                    </tr>
                    </thead>
                </table>
            </div>

            <div data-options="region:'east',collapsible:false" style="width:50%;overflow: hidden">
                <table id="cpd_tt" class="easyui-datagrid" style="width:100%;height:100%" method="get"
                       url="/componentParameterDetail/"  singleSelect="true"
                >
                    <thead>
                    <tr>
                        <th field="compParamDetName" style="width:95%;">参数属性</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="hiddenid" th:value="${param.wareId == null ? '' : param.wareId[0]}" />

<script type="text/javascript">
    //<![CDATA[
    $(function () {
        $("#tt").tree({
            queryParams : {
                wareId : $("#hiddenid").val()
            }
        });

        $('#component_tt').datagrid({
            onSelect: function(index, row){
                $('#cp_tt').datagrid('load', {
                    compId : row.compId
                });
            }
        });
        $('#cp_tt').datagrid({
            onSelect: function (index, row) {
                $('#cpd_tt').datagrid('load', {
                    compParamId: row.compParamId
                });
            }
        });
        $('#cpd_tt').datagrid({
            onSelect: function (index, row) {
                $.messager.confirm('警告', '确定添加该标签吗', function (r) {
                    if (r) {
                        $.post("/wareParameterDetail/", {
                            compParamDetId : row.compParamDetId,
                            wareId : $("#hiddenid").val()
                        }, function (data) {
                            var data = data == "success" ? "添加成功" : "添加失败";
                            $.messager.alert('结果', data, 'info');
                            $("#tt").tree("reload");
                        });
                    }
                });
            }
        });
        $('#tt').tree({
            onSelect : function (node) {
                if ($('#tt').tree('isLeaf', node.target)) {
                    $.messager.confirm('警告', '确定删除该标签吗', function (r) {
                        if (r) {
                            $.ajax({
                                url: "/wareParameterDetail/",
                                type: "POST",
                                data: {
                                    _method : "DELETE",
                                    compParamDetId : node.compParamDetId,
                                    wareId : $("#hiddenid").val()
                                },
                                success: function (data) {
                                    var data = data == "success" ? "删除成功" : "删除失败";
                                    $.messager.alert('结果', data, 'info');
                                    $("#tt").tree("reload");
                                }
                            });
                        }
                    });
                }
            }
        });
    });
    //]]>
</script>


</body>
</html>